package com.manshutingyu.common.core.dto;


import com.manshutingyu.common.core.enums.ResultCodeEnums;
import lombok.Data;

import java.io.Serializable;

@Data
public class R<T>  implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String msg;
    private T data;
    public R() {
    }
    public R(Integer code, String msg, T data) {
       this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R success() {
        return new R(200,"",null);
    }
    public static <T> R<T> success(T data) {
        return new R<T>(200,"", data);
    }
    public static <T> R<T> success(String msg, T data) {
        return new R<T>(200,msg, data);
    }

    public static <T> R<T> error(Integer code, String msg) {
        return new R<T>(code,msg,null);
    }

    public static <T> R<T> error(Integer code, String msg, T data) {
        return new R<T>(code,msg, data);
    }

    public static <T> R<T> error(String message) {
        return new R<>(ResultCodeEnums.FAILED.getCode(), message, null);
    }


    public static <T> R<T> error() {
        return error(ResultCodeEnums.FAILED.getCode(),ResultCodeEnums.FAILED.getMsg(),null);
    }
    /**
     * 参数验证失败返回结果
     *
     * @param message 提示信息
     */
    public static <T> R<T> validateFailed(String message) {
        return new R<>(400, message, null);
    }

    /**
     * 未登录返回结果
     */
    public static <T> R<T> unauthorized(T data) {
        return new R<>(401,"无权限", data);
    }

    /**
     * 未授权返回结果
     */
    public static <T> R<T> forbidden(T data) {
        return new R<>(401,"无权限", data);
    }

}
